package org.dding.msc.exception;

import org.dding.msc.service.ServiceName;

public class ServiceLifecycException extends Exception {

	private static final long serialVersionUID = 5396326230038552249L;

	private volatile ServiceName serviceName;

	public ServiceLifecycException() {
		serviceName = null;
	}

	public ServiceLifecycException(final String msg) {
		super(msg);
		serviceName = null;
	}

	public ServiceLifecycException(final Throwable cause) {
		super(cause);
		serviceName = null;
	}

	public ServiceLifecycException(final String msg, final Throwable cause) {
		super(msg, cause);
		serviceName = null;
	}

	public ServiceLifecycException(final String message, final Throwable cause,
			final ServiceName serviceName) {
		super(message, cause);
		this.serviceName = serviceName;
	}

	public ServiceName getServiceName() {
		return serviceName;
	}

	public void setServiceName(final ServiceName serviceName) {
		this.serviceName = serviceName;
	}

	public String toString() {
		final StringBuilder b = new StringBuilder(getClass().getName());
		if (serviceName != null) {
			b.append(" in ").append(serviceName);
		} else {
			b.append(" in anonymous service");
		}
		final String m = getLocalizedMessage();
		if (m != null) {
			b.append(": ").append(m);
		}
		return b.toString();
	}
}
